﻿public class Solution {
    public bool IsValid(string s)
    {
        Stack<char> stack = new Stack<char>();
        
        foreach (char c in s)
        {
            // 进栈
            switch (c)
            {
                case ' ':
                    continue;
                case '(':
                    stack.Push(')');
                    continue;
                case '[':
                    stack.Push(']');
                    continue;
                case '{':
                    stack.Push('}');
                    continue;
            }
            
            // 出栈
            if (stack.Count == 0 || stack.Pop() != c) return false;
        }
        if (stack.Count != 0) return false;
        return true;
    }

    public static void Main(string[] args)
    {
        string s = "()[]{}";
        Solution solution = new Solution();
        bool res = solution.IsValid(s);
        Console.WriteLine(res);
    }
}